<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>ManageSystem</title>
	<!-- Bootstrap Styles-->
	<link href="/resource/css/login/normalize.css" rel="stylesheet" />
	<!-- Custom Styles-->
	<link href="/resource/css/custom-login.css" rel="stylesheet" />
	<link rel="stylesheet" type="text/css" href="/resource/js/jQueryMessage/css/message.skin.css" />
	<style>
		.sizeSmall{
			width: 50%;
		}
		.sizeSmallImg{
			width: 45%;
			float: right;
			margin-top: -50px;
		}
	</style>
</head>

<body>
<canvas></canvas>
<div class="login">
	<h1>WelCome You</h1>
	<form method="post" id="loginForm">
		<select id="newAddTargetDim" name="userRole"  onchange="changeNum(this.value)">
			<option value="1" selected>教师</option>
			<option value="2">学生</option>
			<option value="3">系统管理员</option>
		</select>
		<input type="text" name="username" placeholder="用户名" required="required" />
		<input type="password" name="password" placeholder="密码" required="required" />
		<div>
			<div class="form-group">
				<input class="form-control sizeSmall" name = "check" type="tel" id="verify_input" placeholder="请输入验证码" maxlength="4">
			</div>
			<a href="javascript:void(0);"  title="点击更换验证码">
				<img class="sizeSmallImg" id="imgVerify" src="" alt="更换验证码" height="36" width="100%" onclick="getVerify(this);">
			</a>
		</div>
		<button type="button" class="btn btn-primary btn-block btn-large" onclick="login();">登录</button>
	</form>
</div>
<div class="copyright">
	Copyright © 2020 I Tech You,我教你  京ICP备6666666号
</div>
<script type="text/javascript" src="/resource/js/jquery.min.js"></script>
<script type="text/javascript" src="/resource/js/jQueryMessage/js/jquery.plugin.message.js"></script>
<script type="text/javascript" src="/resource/js/vector.js"></script>
<script type="text/javascript">
	if (window.frames.length != parent.frames.length) {
		window.parent.location.href = "/admin/user/logout";
	}
	window.onload=function(){
		obj.src = "http://localhost:8866/admin/getVerify?"+Math.random();
	}
	$(function () {
		document.getElementById("imgVerify").click();
    });

	//获取验证码
	function getVerify(obj){
		obj.src = "http://localhost:8866/admin/getVerify?"+Math.random();
	}



	function login(){
		var username = $('input[name="username"]').val();
		var password = $('input[name="password"]').val();
		var userRole = $('select[name="userRole"]').val();
		var check = $('input[name="check"]').val();
		console.log(userRole)
		var data = {
			username : username,
			password : password,
			userRole : userRole,
			check : check,
			rememberMe : false
		};

		$.ajax({
			url : "/admin/user/login",
			contentType : 'application/json',
			data : JSON.stringify(data),
			type : "POST",
			dataType : "JSON",
			success : function(result) {
				console.log(result);
				if(result.success){
					sessionStorage.setItem("douglas", JSON.stringify(result.data));
					$("body").MessageBox({
						type: 'success',
						message:result.info,
						timeout:3000,
						callbak:null
					});
					//登录成功跳转页面的请求
					setTimeout(function() {
						//登录返回
						window.location.href = "/admin/user/toIndex";
					}, 500);
				}else{
					$("body").MessageBox({
						type: 'error',
						message:result.info,
						timeout:3000,
						callbak:null
					});
				}
			}
		});
	}
</script>
</body>
</html>